<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        计算天数改
    </div>
    <input type="text" id="years" placeholder="年份">
    <input type="text" id="month" placeholder="月份">
    <input type="text" id="days" placeholder="天数">
    <button id="btn">计算</button>
    <script>
        var years = document.getElementById("years");
        var month = document.getElementById("month");
        var days = document.getElementById("days");
        var btn = document.getElementById("btn");
        
        btn.onclick = function () {
            var res = 0;
            var feb = 0;
            var year = parseInt(years.value);
            var mon = parseInt(month.value);
            var day = parseInt(days.value);
            if (year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 )) {
                feb = 29 ;
            } else {
                feb = 28 ;
            }
            var num = 0 ;
            while ( num < mon ){
                if ( num == 1 || num == 3 || num == 5 || num == 7 || num == 8 || num == 10 ){
                    res += 31 ;
                } else if ( num == 2 ){
                    res += feb ;
                } else if ( num == 4 || num == 6 || num == 9 || num == 11 ){
                    res += 30 ;
                }
                num ++ ;
            }
            years.value = null ;
            month.value = null ;
            days.value = null ;
            res += day ;
            alert("这是" + year + "年的第" + res + "天");
        }
    </script>
</body>
</html>